const
	CryptoJS = require('crypto-js'),
	// crypto = require('crypto'),
	Base = require('./base/base');

module.exports = class extends Base {
	/**
	 * 编码
	 * @param {string} text 明文
	 * @param {string} key 密钥
	 * @usage /encode?text=123456&key=123456
	 */
	encodeAction(param) {
		nirvana.assert(param.key, 'need key(password)');
		let s = CryptoJS.AES.encrypt(param.text, param.key);
		return s.toString();
	}
	/**
	 * 解码
	 * @param {string} text 密文
	 * @param {string} key 密钥
	 * @usage /decode?text=------&key=123456
	 */
	decodeAction(param) {
		nirvana.assert(param.key, 'need key(password)');
		let s = CryptoJS.AES.decrypt(param.text, param.key);
		return s.toString(CryptoJS.enc.Utf8);
	}
}
